package org.example.controller;

import org.example.entity.ClassEntity;
import org.example.service.ClassResultsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassResultsInfoController {

    @Autowired
    private ClassResultsInfoService classResultsInfoService;

    /**
     * 获取班级某个考试的总成绩
     * @param classId 考试ID
     * @return 班级总成绩
     */
    @GetMapping("/total/{examId}")
    public Float getClassTotalScore(@PathVariable long classId) {
        return classResultsInfoService.getClassTotalScore(classId);
    }

    /**
     * 获取班级某个考试的平均成绩
     * @param examId 考试ID
     * @return 班级平均成绩
     */
    @GetMapping("/average/{examId}")
    public Float getClassAverageScore(@PathVariable long examId) {
        return classResultsInfoService.getClassAverageScore(examId);
    }

    /**
     * 获取班级某个考试的最高成绩
     * @param examId 考试ID
     * @return 班级最高成绩
     */
    @GetMapping("/highest/{examId}")
    public Float getClassHighestScore(@PathVariable long examId) {
        return classResultsInfoService.getClassHighestScore(examId);
    }

    /**
     * 获取班级某个考试的通过人数
     * @param examId 考试ID
     * @param passingScore 及格分数
     * @return 班级通过人数
     */
    @GetMapping("/pass-count")
    public int getClassPassCount(@RequestParam long examId, @RequestParam Float passingScore) {
        return classResultsInfoService.getClassPassCount(examId, passingScore);
    }

    /**
     * 获取班级某个考试的所有学生成绩
     * @param examId 考试ID
     * @return 班级成绩列表
     */
    @GetMapping("/scores/{examId}")
    public List<ClassEntity> getClassScores(@PathVariable long examId) {
        return classResultsInfoService.getClassScores(examId);
    }
}